package com.kexio.file.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.kexio.common.entity.BaseEntity;

import io.swagger.v3.oas.annotations.media.Schema;

/**
 * 文件存储配置实体
 * 支持多种存储配置的动态管理
 * 
 * @author Kexio Team
 * @since 1.0.0
 */
@Schema(description = "文件存储配置")
@TableName("sys_file_storage_config")
public class FileStorageConfig extends BaseEntity {

    @Schema(description = "配置ID")
    @TableId(value = "id", type = IdType.ASSIGN_UUID)
    private String id;

    @Schema(description = "配置名称", example = "生产环境MinIO")
    @TableField("config_name")
    private String configName;

    @Schema(description = "存储类型", example = "minio", allowableValues = {"local", "minio", "oss", "cos", "qcloud", "huawei"})
    @TableField("config_type")
    private String configType;

    @Schema(description = "配置描述")
    @TableField("description")
    private String description;

    @Schema(description = "配置参数JSON")
    @TableField("config_params")
    private String configParams;

    @Schema(description = "是否启用")
    @TableField("is_enabled")
    private Boolean isEnabled;

    @Schema(description = "是否为默认配置")
    @TableField("is_default")
    private Boolean isDefault;

    @Schema(description = "排序字段")
    @TableField("sort_order")
    private Integer sortOrder;

    // ==================== 构造方法 ====================

    public FileStorageConfig() {
        this.isEnabled = true;
        this.isDefault = false;
        this.sortOrder = 0;
    }

    public FileStorageConfig(String configName, String configType, String configParams) {
        this();
        this.configName = configName;
        this.configType = configType;
        this.configParams = configParams;
    }

    // ==================== Getters and Setters ====================

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getConfigName() {
        return configName;
    }

    public void setConfigName(String configName) {
        this.configName = configName;
    }

    public String getConfigType() {
        return configType;
    }

    public void setConfigType(String configType) {
        this.configType = configType;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getConfigParams() {
        return configParams;
    }

    public void setConfigParams(String configParams) {
        this.configParams = configParams;
    }

    public Boolean getIsEnabled() {
        return isEnabled;
    }

    public void setIsEnabled(Boolean isEnabled) {
        this.isEnabled = isEnabled;
    }

    public Boolean getIsDefault() {
        return isDefault;
    }

    public void setIsDefault(Boolean isDefault) {
        this.isDefault = isDefault;
    }

    public Integer getSortOrder() {
        return sortOrder;
    }

    public void setSortOrder(Integer sortOrder) {
        this.sortOrder = sortOrder;
    }

    // ==================== 工具方法 ====================

    /**
     * 获取存储类型的显示名称
     */
    public String getConfigTypeDisplayName() {
        if (configType == null) return "未知";
        
        switch (configType.toLowerCase()) {
            case "local": return "本地存储";
            case "minio": return "MinIO对象存储";
            case "oss": return "阿里云OSS";
            case "cos": return "腾讯云COS";
            case "qcloud": return "腾讯云";
            case "huawei": return "华为云OBS";
            default: return configType.toUpperCase();
        }
    }

    /**
     * 获取启用状态的显示文本
     */
    public String getEnabledStatusText() {
        return Boolean.TRUE.equals(isEnabled) ? "启用" : "禁用";
    }

    /**
     * 获取默认配置的显示文本
     */
    public String getDefaultStatusText() {
        return Boolean.TRUE.equals(isDefault) ? "默认" : "";
    }

    /**
     * 检查配置是否可用（启用且不为空）
     */
    public boolean isAvailable() {
        return Boolean.TRUE.equals(isEnabled) && 
               configParams != null && 
               !configParams.trim().isEmpty();
    }

    @Override
    public String toString() {
        return "FileStorageConfig{" +
                "id='" + id + '\'' +
                ", configName='" + configName + '\'' +
                ", configType='" + configType + '\'' +
                ", description='" + description + '\'' +
                ", isEnabled=" + isEnabled +
                ", isDefault=" + isDefault +
                ", sortOrder=" + sortOrder +
                '}';
    }
}
